package luj.tool.jnproxyan.proxy.network.socks.request.op;

import com.google.common.base.Preconditions;
import luj.tool.jnproxyan.proxy.network.socks.actor.root.Socks5Actor;
import luj.tool.jnproxyan.proxy.network.socks.request.SocksRequest;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RequestByIdGetter {

  public RequestByIdGetter inject(Socks5Actor actor, Long reqId) {
    return inject(actor.getRequestMap(), reqId);
  }

  public RequestByIdGetter inject(Map<Long, SocksRequest> reqMap, Long reqId) {
    RequestByIdGetter result = new RequestByIdGetter();
    result._reqMap = reqMap;
    result._reqId = reqId;
    return result;
  }

  public SocksRequest getReq() {
    SocksRequest req = _reqMap.get(_reqId);
    return Preconditions.checkNotNull(req, _reqId);
  }

  Map<Long, SocksRequest> _reqMap;

  Long _reqId;
}
